package com.chenfan.mcn.controller;

import com.chenfan.mcn.annotations.ActionTracing;
import com.chenfan.mcn.extension.Res;
import com.chenfan.mcn.service.PlaceOnFileService;
import com.chenfan.privilege.common.config.UrlAuth;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 归档操作
 *
 * @Author liuyang
 * @Date 2021/9/30
 * @Time 11:27
 * @Version V1.0
 **/
@RestController
@RequestMapping("/archive")
public class PlaceOnFileController {

    @Autowired
    private PlaceOnFileService placeOnFileService;

    /**
     * 盖章
     *
     * @param contractCode  合同编号
     * @param archivingCode 归档编号
     */
    @ActionTracing("盖章")
    @GetMapping("/seal")
    @UrlAuth({"yearContract_seal","revenueContract_seal","procurementContract_seal","redsContract_seal","annualRebateApproval_seal"})
    public Res<Object> seal(String contractCode, String archivingCode) {
        placeOnFileService.seal(contractCode, archivingCode);
        return Res.ok();
    }

    /**
     * 归档
     *
     * @param contractCode 合同编号
     */
    @ActionTracing("归档")
    @GetMapping("/file")
    @UrlAuth({"procurementContract_file","annualRebateApproval_file","redsContract_file","revenueContract_isFile","yearContract_file"})
    public Res<Object> file(String contractCode) {
        placeOnFileService.file(contractCode);
        return Res.ok();
    }


    /**
     * 归档编号生成规则
     *
     * @param contractCode 合同编号
     * @return 归档编号
     */
    @GetMapping("/archiveNumber")
    @UrlAuth({"yearContract_seal","revenueContract_seal","procurementContract_seal","redsContract_seal","annualRebateApproval_seal"})
    public Res<String> getArchiveCode(String contractCode) {
        return Res.ok(placeOnFileService.getArchiveCode(contractCode));
    }
}
